/**
 * ...
 * @author Franco Ponticelli
 */

package uform.property;

import utest.Assert;
import uform.property.Property;

class TestProperty extends Test
{
	public function testSetGet()
	{
		var property = new Property();
		Assert.isNull(property.get());
		property.set("haxe");
		Assert.equals("haxe", property.get());
		property.reset();
		Assert.isNull(property.get());
	}
	
	public function testDefault()
	{
		var property = new Property("");
		Assert.equals("", property.get());
		property.set("haxe");
		Assert.equals("haxe", property.get());
		property.reset();
		Assert.equals("", property.get());
		property.set(null);
		Assert.isNull(property.getValue());
		Assert.equals("", property.get());
		property.setDefault(null);
		Assert.isNull(property.get());
	}
	
	public function testOnChange()
	{
		var old = null, current = null, counter = 0;
		
		var property = new Property("");
		property.onChange.add(function() { counter++; } );
		Assert.equals("", property.get());
		Assert.equals(0, counter);
		property.set("haxe");
		Assert.equals(1, counter);
		Assert.equals("", property.getOld());
		Assert.equals("haxe", property.get());
		property.set("haxe");
		Assert.equals(1, counter);
		
		property.reset();
		Assert.equals(2, counter);
		Assert.equals("haxe", property.getOld());
		Assert.equals("", property.get());
		property.reset();
		Assert.equals(2, counter);
	}
	
	public function new();
}